package com.zh.home

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import com.zh.common.base.BaseFragment
import com.zh.common.ktx.clickSingleListener
import com.zh.common.ktx.launch
import com.zh.common.ktx.registerForResult
import com.zh.common.ktx.toast
import com.zh.home.databinding.FragmentHomeBinding

class HomeFragment : BaseFragment<FragmentHomeBinding>() {

//    private lateinit var launch: ActivityResultLauncher<Intent>

    private val launch = registerForResult {
        toast(it.data?.getStringExtra("name"))
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
//        launch =
//            registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
//                if (Activity.RESULT_OK == it.resultCode) {
//                    toast(it.data?.getStringExtra("name"))
//                }
//            }
    }

    override fun initView(savedInstanceState: Bundle?) {
        viewBinding.tvGo.clickSingleListener {
            launch.launch(requireActivity(),INext::class.java)
//            launch.launch(Intent(activity, INext::class.java))
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        launch.unregister()
    }
}